#pragma once

#include <CoreWindow.h>
#include <cassert>

template<class T>
class console_screen_base
{
public:

	console_screen_base(int x = 0, int y = 0, int high = 5, int wide = 10, 
		T up = 0, T down = 0, T left = 0, T right = 0,
		T top_left = 0, T bottom_left = 0, T top_right = 0, T bottom_right = 0)
		:_x(x)
		,_y(y)
		,_high(high)
		,_wide(wide)
		,_up(up)
		,_down(down)
		,_left(left)
		,_right(right)
		,_top_left(top_left)
		,_bottom_left(bottom_left)
		,_top_right(top_right)
		,_bottom_right(bottom_right)
	{
		assert(x >= 0 && y >= 0);
		assert(high >= 0 && wide >= 0);
	}

	void changePos(int x, int y)
	{
		assert(x >= 0 && y >= 0);

		_x = x;
		_y = y;
	}

	void changeFrameSize(int high, int wide)
	{
		assert(high >= 0 && wide >= 0);

		_high = high;
		_wide = wide;
	}

	void changeSide(T up = 0, T down = 0, T left = 0, T right = 0)
	{
		_up = up == 0 ? _up : up;
		_down = down == 0 ? _down : down;
		_left = left == 0 ? _left : left;
		_right = right == 0 ? _right : right;
	}

	void changeCorner(T top_left = 0, T bottom_left = 0, T top_right = 0, T bottom_right = 0)
	{
		_top_left		= top_left		== 0 ? _top_left		: top_left;
		_bottom_left	= bottom_left	== 0 ? _bottom_left		: bottom_left;
		_top_right		= top_right		== 0 ? _top_right		: top_right;
		_bottom_right	= bottom_right	== 0 ? _bottom_right	: bottom_right;
	}

	void changeUp(T up)
	{
		_up = up;
	}

	void changeDown(T down)
	{
		_down = down;
	}

	void changeLeft(T left)
	{
		_left = left;
	}

	void changeRight(T right)
	{
		_right = right;
	}

	void changeTopLeft(T top_left)
	{
		_top_left = top_left;
	}

	void changeTopRight(T top_right)
	{
		_top_right = top_right;
	}

	void changeBottomLeft(T bottom_left)
	{
		_bottom_left = bottom_left;
	}

	void changeBottomRight(T bottom_right)
	{
		_bottom_right = bottom_right;
	}

protected:

	static void SetPos(int x, int y)
	{
		COORD pos = { x, y };
		SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
	}

	void printFrame()
	{
		if (_up != 0)
		{
			printCharUp();
		}
		if (_down != 0)
		{
			printCharDown();
		}
		if (_left != 0)
		{
			printCharLeft();
		}
		if (_right != 0)
		{
			printCharRight();
		}
		if (_top_left != 0 ||
			_top_right != 0 ||
			_bottom_left != 0 ||
			_bottom_right != 0)
		{
			printCharCorner();
		}
	}

	virtual void printCharUp() = 0;

	virtual void printCharDown() = 0;

	virtual void printCharLeft() = 0;

	virtual void printCharRight() = 0;
	
	virtual void printCharCorner() = 0;

	void cleanFrame()
	{
		if (_up != 0)
		{
			cleanCharUp();
		}
		if (_down != 0)
		{
			cleanCharDown();
		}
		if (_left != 0)
		{
			cleanCharLeft();
		}
		if (_right != 0)
		{
			cleanCharRight();
		}
		if (_top_left != 0 ||
			_top_right != 0 ||
			_bottom_left != 0 ||
			_bottom_right != 0)
		{
			cleanCharCorner();
		}
	}

	virtual void cleanCharUp() = 0;

	virtual void cleanCharDown() = 0;

	virtual void cleanCharLeft() = 0;

	virtual void cleanCharRight() = 0;

	virtual void cleanCharCorner() = 0;

protected:

	int _x;
	int _y;

	int _high;
	int _wide;

	T _up;
	T _down;
	T _left;
	T _right;

	T _top_left = 0;
	T _bottom_left = 0;
	T _top_right = 0;
	T _bottom_right = 0;

};


